<!DOCTYPE HTML>
<html lang="zh-cn"
      xmlns:th="http://www.thymeleaf.org" xmlns:v-bind="http://www.w3.org/1999/xhtml"
      xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>

    <META HTTP-EQUIV="Pragma" CONTENT="no-cache"/>
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"/>
    <META HTTP-EQUIV="Expires" CONTENT="0"/>

    <title>目录页</title>
    <link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body onload="">

<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>

<div class="container">
    <br/>
    <br/>
    <div id="app">
        <form class="form-horizontal" method="post" v-bind:action="'/submit'+type" role="form">
            <div class="form-group">
                <label for="blog_title" class="col-sm-2 control-label">Title</label>
                <div class="col-sm-10">
                    <input type="text" name="title" class="form-control" id="blog_title" placeholder="请输入Title" />
                </div>
            </div>
            <div class="form-group">
                <label for="blog_content" class="col-sm-2 control-label">Content</label>
                <div class="col-sm-10">
                    <textarea class="form-control" name="content" rows="18" id="blog_content" placeholder="请输入内容"></textarea>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                aria-haspopup="true" aria-expanded="false">Type<span class="caret"></span></button>
                        <ul class="dropdown-menu">
                            <li><a v-on:click="changeType('Essay')">Essay</a></li>
                            <li><a v-on:click="changeType('Blog')">Blog</a></li>
                        </ul>
                    </div><!-- /btn-group -->
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" class="btn btn-default" onclick="submitClick()">Convert Markdown</button>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-default">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>

</body>
<!--VUE-->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://cdn.bootcss.com/marked/0.3.6/marked.min.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            type: 'Essay'
        },
        methods : {
            changeType : function (type) {
                this.type = type;
            }
        }
    })

    function submitClick() {
        convertMarkdown()
    }

    function convertMarkdown() {
        var blog_content = $('#blog_content')
        var my_input = blog_content.val()
        console.log(my_input)
        my_input = marked(my_input)
        console.log(my_input)
        blog_content.val(my_input)
    }
</script>
</html>